/*** 本文件由CSMIS2.0-ModelCreater(UTF-8)工具辅助生成，版本1.0 ***/

package com.ce.sys.role.logic.search;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.ce.framework.datamaintain.logic.ISQLMapper;
import com.ce.framework.datamaintain.logic.SQLSearchCondition;
import com.ce.framework.exception.AppException;
import com.ce.framework.util.StringUtil;
import com.ce.sys.login.model.User;
import com.ce.sys.role.view.SysRoleView;

/**
* 嫦娥软件有限公司 版权所有 2013
* 创建人：　andy
* 创建日期：2010-10-25
* 创建时间：09:15:59
* 功能描述：系统角色表 [SYS_T_ROLE]条件过滤类
* ==============================================
* 修改历史
* 修改人		修改时间		修改原因
*
* ==============================================
*/
public class SysRoleSearchCondition  extends SQLSearchCondition
	implements ISQLMapper
{

	
	private String names; //角色名称
	
	private String cxMenuId;

	private String adminUser;
	
	public String getNames() {
		return names;
	}

	public void setNames(String names) {
		this.names = names;
	}


	public String getSearchSql() throws AppException {
		
		String sql = "select t.*, NVL(p.vc_name,'系统管理员') vc_user_name FROM SYS_T_ROLE t,SYS_T_PERSON p where t.VC_DEL$FLAG = 0" +
				" AND t.vc_type = p.vc_id(+)";
		if(StringUtil.isNotBlank(names)){
			sql = sql + " and t.VC_NAME like '%"+this.getSafeValue(names)+"%'";
		}
//		if(StringUtil.isNotBlank(cxMenuId)){
//			sql = sql + " and t.VC_TYPE = '"+this.getSafeValue(this.cxMenuId)+"'";
//		}else if(!User.getUser().isSuperUser()){
//			sql = sql + " and t.VC_TYPE = '0'";
//		}
		if(!User.getUser().isAdmin()) {
		    sql = sql + " and (t.VC_TYPE = '"+User.getUserId()+"' or t.vc_public='1') ";
		}
//		else {
//		    if(StringUtil.isNotBlank(cxMenuId)){
//			sql = sql + " and t.VC_TYPE = '"+this.getSafeValue(this.cxMenuId)+"'";
//		    }else{
//			sql = sql + " and t.VC_TYPE = '0'";
//		    }
//		}
		if(StringUtil.isNotBlank(adminUser)) {
			sql += " and  t.vc_type ='"+this.adminUser+"'";
		}
		if(StringUtil.isNotBlank(this.order)){
			if("vcSeq".equals(this.sort))
				sql = sql + " order by t.VC_SEQ "+this.order;
			if("vcName".equals(this.sort))
				sql = sql + " order by t.VC_NAME "+this.order;
			if("vcUserName".equals(this.sort))
				sql = sql + " order by p.VC_NAME "+this.order;
		}else{
			sql = sql + " order by t.VC_SEQ asc";
		}
		return sql;
	}
	
	public Object fromSQLQuery(ResultSet rs, int num) {
		SysRoleView view = new SysRoleView();
		try {

			view.setVcId(rs.getString("VC_ID"));
			view.setVcName(rs.getString("VC_NAME"));
			view.setVcSeq(rs.getInt("VC_SEQ"));
			view.setVcType(rs.getString("VC_TYPE"));
			view.setVcMemo(rs.getString("VC_MEMO"));
			view.setVcDelFlag(rs.getInt("VC_DEL$FLAG"));
			view.setVcUserName(rs.getString("VC_USER_NAME"));

		} catch (SQLException e) {
			
			e.printStackTrace();
		}
		return view;
	}
	
	public ISQLMapper getSQLMapper() {
		
		return this;
	}

	public String getCxMenuId() {
		return cxMenuId;
	}

	public void setCxMenuId(String cxMenuId) {
		this.cxMenuId = cxMenuId;
	}

	public String getAdminUser() {
	    return adminUser;
	}

	public void setAdminUser(String adminUser) {
	    this.adminUser = adminUser;
	}

	
}

